Repository navigation
[Air #1938] feat: Show workspace images inline in Decisions tab items - #1939
Open
waleedkadous wants to merge 7 commits into
Open
waleedkadous wants to merge 7 commits into
waleedkadous wants to merge 7 commits into
Conversation
New read-only route GET /api/decisions/image?path= serves one image an item references. Relative paths resolve against the decisions file's directory and /-rooted paths against the workspace root. It fails closed: containment is checked before and after following symlinks, the extension allowlist is checked on both the link and its target, files over 10 MB are refused, and responses carry nosniff and a sandbox CSP. DecisionsMarkdown parks every non-http(s) image source in an inert document, so the browser never requests a workspace path itself. It then fetches each image with the key, shows it from an object URL (revoked on cleanup), and shows an "Image not loaded" note for refusals and other schemes. A click opens a workspace image on a page holding only an <img> of it, so an SVG never runs as a dashboard-origin document. Also fixes in place: React 19 re-sets dangerouslySetInnerHTML whenever the prop object changes identity, so every re-render undid the link rule (a relative link got its href back). The markup object is now memoized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… race, MarkdownView memo)
- Pin the srcset guard with a test: a raw-HTML <img srcset> would otherwise
make the browser load a workspace candidate itself.
- An image source's ?query or #fragment is not part of the file name; strip it
before the path is sent, so shot.png?v=2 loads instead of being refused as
not-an-image.
- An image that goes between being located and being read is not-found, not a
generic 500, matching readBytes for the decisions file.
- Leave Tower's global Cache-Control: no-store in place on the image route.
- MarkdownView memoizes its { __html } object too, so the React 19 identity
trap is fixed where it starts for any other host.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An item in the Decisions tab can now show an image saved in the workspace:
renders inline in the card, in item bodies, their question/answer entries, and the ruled section.http(s)images work exactly as before.Closes #1938
Playwright, real Tower and browser: a 1600 px PNG beside the decisions file (scaled to the card), a
/-rooted SVG, anhttp(s)image, and two refused images: one missing, one escaping the workspace through../../...What Changed
Server:
GET /workspace/<enc>/api/decisions/image?path=<path>(servers/decisions/routes.ts,handleDecisionsImage), key-gated like the other decisions routes. It is the first decisions route that takes a path, so it fails closed:/resolves against the workspace root. No decisions file (or one outside the workspace) means no images, through the existinglocate().png jpg jpeg gif webp svg) on the requested path and on its realpath target, so aninnocent.pngsymlink to.envis refused.statbeforeread: not a regular file isnot-found(a FIFO named*.pngis never opened); over 10 MB is refused.Content-Typefrom the existinggetMimeTypeForFile,X-Content-Type-Options: nosniff, plus asandboxCSP. Tower's globalCache-Control: no-storestands. A file that disappears between being located and being read isnot-found, not a 500.{ ok: false, code, message }shape and codes (invalid-request,not-found,outside-workspace,config-error) plus two new ones:not-an-image(415) andimage-too-large(413).Client:
DecisionsMarkdown(DecisionsView.tsx) andfetchDecisionImage(lib/api.ts):http(s)is parked indata-decisions-srcinside an inertDOMParserdocument before the HTML reaches the page, andsrcsetis dropped from every<img>. Rendering throughMarkdownView's innerHTML would have let the browser start a native load of each relative path against the dashboard URL (a 401 and a Tower WARN per image) before any effect could run. So the view now callsrenderMarkdowndirectly; the shared renderer is unchanged.?query/#fragment, which are not part of a file name) is fetched with the key, shown from a blob object URL, and revoked when the markdown changes or the card leaves. An in-flight load is aborted on cleanup.data:/ other-scheme / protocol-relative source, is replaced by a dashed note: Image not loaded + alt text + the path as written, with the reason in its tooltip. No broken-image icon.max-width: 100%,max-height: 480px,object-fit: contain. A click opens the image full size in a new tab.Docs, both trees: an "Images" rule in "What the tab reads" (
resources/decision-protocol.md) and a sentence in the Decisions tab section ofresources/commands/agent-farm.md, both suggestingdecision-assets/beside the decisions file.arch.md(route + view) and alessons-learned.mdentry are updated.Key Decisions
<img>of the blob (revoked after 60 s). This keeps the issue's "SVG only through<img>" rule true for the full-size view too.http(s)images open themselves, like links.**Your word:**, leave the id, options, writability and ruling splice unchanged. The fingerprint is the item's text as before, computed server-side, so image load state cannot reach it.Adjacent bug fixed in place
React 19 compares
dangerouslySetInnerHTMLby object identity, not by the__htmlstring. Any inline{ __html: html }(as inMarkdownView) re-sets the HTML on every render. In the Decisions tab every card re-renders on a poll that brings a new document, on a ruling, and on each draft keystroke. Each re-render undid the link rule: a relative link got itshrefback, so a middle-click could open it. The effect, keyed on the unchanged string, never re-ran. I confirmed this against the shippedMarkdownViewwith a throwaway test. It surfaced here because it wiped loaded images in the Playwright case. Fix:DecisionsMarkdownmemoizes the{ __html }object itself, and so does the sharedMarkdownView(artifact-canvas), so the trap is fixed where it starts.MarkdownViewhas no remaining production caller in this repo; this protects the package's other consumers, and the reader's text selection. Tests: a view test re-renders with a fresh document and the same markdown and checks that both the image and the link rule survive; aMarkdownViewtest checks that the rendered DOM survives a same-source re-render and is replaced on a new source.Test Plan
decisions-routes.test.ts, 18 new): a file vanishing between locate and read (404); relative and/-rooted resolution, resolution against a configured decisions path; refusal of../..,/.., a sibling dir sharing the workspace's name prefix, an absolute filesystem path, a symlink out, a symlinked dir out; serving an in-workspace symlink; non-image extensions (including.env,.png.txt) and an image-named symlink to a non-image; size limit at and over 10 MB; missing file, directory, path through a file; empty/NUL path; no decisions file.decisions-parse.test.ts): image lines in the body and adjacent to**Your word:**.DecisionsView.images.test.tsx, 18 new): keyed fetch and object URL;/-rooted and percent-encoded paths;?query/#fragmentstripped;srcsetdropped (raw-HTML<img srcset>); all three render sites; refused / network-failure / non-image response / decode error leave a not-loaded note;data:,ftp:,//hostnever fetched;http(s)untouched; revoke on markdown change and unmount; abort in flight; re-render keeps image and link rule; click behaviours.decisions-tab.test.ts, new case): real Tower and Chromium. A browser-drawn PNG beside the decisions file, a/-rooted SVG and a routedhttp(s)image all decode; a 1600 px image stays within the card; missing and escaping images show the note; no native request for any.png/.svgpath reaches Tower; the click opens a full-size tab; ruling on the item writes exactly the word, and the images stay loaded. Full decisions suite 14/14; the image case 5/5 on--repeat-each=5. Re-run once on the final head3d545e074after the review fixes, with a rebuilt dashboard: 14/14.MarkdownViewtest (artifact-canvas, new): the rendered DOM survives a same-source re-render.build+testschecks pass (packages/codev, 8263 tests).apps/webtsc -b,packages/codevandpackages/artifact-canvastsc --noEmit.3d545e074,suites=true): green on attempt 4. All 11 jobs pass (2 skipped by design); Unit tests on Node 22 and on Node 24 each pass 405 files. Before that, Unit tests (Node 22) failed three times, on three different non-test causes. The decisions tests (routes incl. all new image cases, parse, splice) pass on Windows under Node 22 and Node 24 in every attempt, and Node 24 unit tests pass in full.pir-1233-session-launch-loop.test.ts > failures slower than the threshold never trip the degrade fallback(3.7 s);Flaky Tests
Porch's
testscheck failed twice before passing, each time with 5 s timeouts in pre-existing process-spawning tests unrelated to this change, a different set each run, while the machine's load average was 30–39 (other workspaces). Each passes in isolation (72/72). The check passed once load fell to 11. None was edited, skipped, or given a longer timeout.packages/codev/src/agent-farm/__tests__/bugfix-1267-launch-loop.test.ts: "keeps resuming across a CRASH", "the switch to fresh is sticky"packages/codev/src/agent-farm/__tests__/ide-command.test.ts: "ideInstall … reports the installed server version on success"packages/codev/src/commands/consult/__tests__/agy-auth-cache.test.ts: "spawns agy at most once across a 5-wide burst when unauthenticated"packages/codev/src/commands/consult/__tests__/tripwire-wiring.test.ts: "fires even when the lane throws"packages/codev/src/agent-farm/__tests__/pir-1233-session-launch-loop.test.ts: "failures slower than the threshold never trip the degrade fallback" (failed in attempt 1 of the Windows run above, then passed in attempt 3).Separately, locally on Node 26, 93
apps/webterminal / keyboard / toolbar tests fail onlocalStorage.getItemof undefined (Node's built-in web storage shadows jsdom's). WithNODE_OPTIONS=--no-experimental-webstoragethe whole web suite passes (598). This predates the change and is environment-only; the new view test supplies the key the way Tower injects it, so it passes either way.Review Notes
locateImage/handleDecisionsImageinroutes.ts, andopenFullSize+decisionsHtmlinDecisionsView.tsx.<img>(markdown images and raw-HTML<img>,srcsetincluded). Not done (out of scope per the issue):<picture>/<source>,<video poster>, CSSurl()in raw-HTMLstyleattributes, which can still make the browser request a path natively (a harmless 401), and image keyboard focus.path.join/path.resolve; the absolute-path test expectsoutside-workspaceonwin32. The Windows workflow ran (see Test Plan).3d545e074: a test pinning thesrcsetguard,?query/#fragmentstripping, the read-race 404, keeping Tower'sno-store, theMarkdownViewmemo, and scoping the "no native request" claim (above). Not changed:status.yamlgate fields, which porch fills at the gate.🤖 Generated with Claude Code